﻿using System;
using UnityEngine.UI;
using UnityEngine;


public class Util{

	private static int rep = 0;

	public static long timeStamp ()
	{
		System.TimeSpan ts = System.DateTime.UtcNow - new System.DateTime (1970, 1, 1, 0, 0, 0, 0);  
		return System.Convert.ToInt64 (ts.TotalSeconds);
	}

	public static string nowTimeymd ()
	{
		return System.DateTime.Now.ToString ("yyyy-MM-dd HH:mm:ss", System.Globalization.DateTimeFormatInfo.InvariantInfo);
	}

	public static void setAlpha(Image img){
		Color c = img.color;
		img.color = new Color (c.r, c.g, c.b, 0);
	}

	public static Canvas getCanvas(GameObject obj){

		Transform t = obj.transform.parent;
		while (t != null) {
			if (t.GetComponent<Canvas> () != null) {
				return t.GetComponent<Canvas> ();
			}
			t = t.parent;
		}

		return null;

	}


	public static string getRanomString(int codeCount)
	{
		string str = string.Empty;
		long num2 = DateTime.Now.Ticks + (Util.rep++);

		System.Random random = new System.Random(((int)(((ulong)num2) & 0xffffffffL)) | ((int)(num2 >> Util.rep)));
		for (int i = 0; i < codeCount; i++)
		{
			char ch;
			int num = random.Next();
			if ((num % 2) == 0)
			{
				ch = (char)(0x30 + ((ushort)(num % 10)));
			}
			else
			{
				ch = (char)(0x41 + ((ushort)(num % 0x1a)));
			}
			str = str + ch.ToString();
		}
		return str;
	}

}